// === Nodejs已废弃的API,报警告，请参考 crypto-createCipheriv.js===

// 引入crypto加密模块 - Nodejs内置模块
let crypto;
try {
  crypto = require('crypto');
} catch (err) {
  console.log('crypto support is disabled!');
}

// 加盐(加密的秘钥)
const secret = "hellom";

// 加密
function encrypt(password){
    const cipher = crypto.createCipher('aes192',secret);
    cipher.update(password);
    const cryptoPassword = cipher.final('hex');
    return cryptoPassword;
}

// 解密
function decrypt(password){
    const deCipher = crypto.createDecipher('aes192',secret);
    deCipher.update(password,'hex');
    const cryptoPassword = deCipher.final('utf-8');
    return cryptoPassword;
}

module.exports = { encrypt,decrypt }
